package com.autumn.cloud.demo.consumer.services.impl;

import com.alibaba.dubbo.config.annotation.Reference;
import com.autumn.cloud.demo.consumer.services.OrderAppService;
import com.autumn.cloud.demo.dubbo.api.bo.OrderInfoBO;
import com.autumn.cloud.demo.dubbo.api.services.OrderApiService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Random;

/**
 * <p>
 * </p>
 *
 * @description TODO
 * @author: 老码农
 * @create: 2020-12-16 01:01
 **/
@Service
public class OrderAppServiceImpl implements OrderAppService {

    // dubbo 引用 api
    @Reference(group = "g1")
    private OrderApiService orderApiService1;

    @Reference(group = "g2")
    private OrderApiService orderApiService2;

    @Override
    public List<OrderInfoBO> orders() {
        Random random = new Random();
        int num = random.nextInt(10);
        List<OrderInfoBO> orderInfos;
        if (num % 2 != 0) {
            orderInfos = orderApiService1.orders();
        } else {
            orderInfos = orderApiService2.orders();
        }
        for (OrderInfoBO orderInfo : orderInfos) {
            orderInfo.setOrderTitle(orderInfo.getOrderTitle() + "(dubbo 转发)");
        }
        return orderInfos;
    }
}
